/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * 
 * Copyright 2010 yura, Version 2.0 (the "License");
 *
 * you may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 *
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 
 * Unless required by applicable law or agreed to in writing, software
 *
 * distributed under the License is distributed on an "AS IS" BASIS,
 *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 *
 * limitations under the License.
 */

package org.opu.doc2db.document.datadocument.io;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.opu.doc2db.document.datadocument.Document;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

/**
 * This class work with XML description of document
 *
 * @author yura
 */
public class DefaultDocumentReader implements DocumentReader{

    protected Serializer serializer;

    public DefaultDocumentReader() {
        serializer = new Persister();
    }

    @Override
    public Document parseDocument(InputStream in) throws IOException {
        try {
            return serializer.read(Document.class, in);
        } catch (Exception ex) {
            throw new IOException(ex);
        }
    }

    @Override
    public Document parseDocument(Reader reader) throws IOException {
        try {
            return serializer.read(Document.class, reader);
        } catch (Exception ex) {
            throw new IOException(ex);
        }
    }

    @Override
    public Document parseDocument(File file) throws IOException {
        try {
            return serializer.read(Document.class, file);
        } catch (Exception ex) {
            throw new IOException(ex);
        }
    }

}
